package 
{
	import flash.display.Bitmap;
	import flash.display.InteractiveObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;	
	import mx.core.BitmapAsset;
	
	/**
	 * ...
	 * @author KhanhNHV
	 */
	public class Main extends Sprite 
	{
		[Embed(source = "../lib/title.jpg")]
		private var LogoClass:Class;
		[Embed(source = "../lib/background.jpg")]
		private var BackgroundClass:Class;
		var text:QuestionField;
		var playfield:PlayField;
		var listQuestion:Array = ["What institution support poor countries in economic development?", "How to describe the uncertainty that companies or individuals will be unable to make the required payments on their debt obligations?", 
								"What is the level of satisfaction or enjoyment derived from a particular basket of items?", "What is the reason why real GDP remain constant but real GDP rises?", "What kind of asset issued by the company that gives the right but not the obligation to take up shares in a company at an agreed-upon price within a certain period or on a specific date.", "The first bank’s branch from Vietnam operates in Europe.",
								"Who is willing to take risk by buying and selling contracts through capital gains to make profits?", "One of the ways for your entire portfolio to avoid the impact of a decline of any one security by mingling different assets in the portfolio.", "9.	What is the method the companies use to distribute their profits?",
								"The places provide companies with the facility to raise capital for expansion through selling shares to the investing public."]
		var enableSound:Boolean = false;
		var countdownTime:Number = 10;
		public function Main():void 
		{
			var logoBmp:BitmapAsset = new LogoClass() as BitmapAsset;			
			logoBmp.x = 500;
			var backgroundBmp:BitmapAsset = new BackgroundClass() as BitmapAsset;
			backgroundBmp.width = 1280;
			backgroundBmp.height = 1024;
			backgroundBmp.alpha = 0.5
			this.addChild(backgroundBmp);
			this.addChild(logoBmp);
			text = new QuestionField();
			playfield = new PlayField();
			if (stage) init();
			var xmlLoader: URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, setConfig);
			xmlLoader.load(new URLRequest("config.xml"));			
			
		}
		
		function setConfig(e:Event)
		{
			XML.ignoreWhitespace = true;
			var config:XML = new XML(e.target.data);
			enableSound = Boolean(config.sound[0].text());
			countdownTime = Number(config.time[0].text());
			text.tickNumber = 30;
		}
		
		
		private function init(e:Event = null):void 
		{
			this.addChild(text);			
			this.addChild(playfield);			
			playfield. y = 200;
			//text.transitionIn();
			this.addEventListener(CustomEvent.FOCUSTEXTCOMPLETED, showQuestion);
			this.addEventListener(CustomEvent.RETURNTONORMAL, showPuzzle);
			
			// entry point
		}
		
		private function showQuestion(ce:CustomEvent)
		{			
			text.textQuestion.text = listQuestion[ce.index];
			text.transitionIn();
			playfield.minimize();
		}
		
		private function showPuzzle(ce:CustomEvent)
		{
			text.transitionOut();
			playfield.maximize();
		}
		
		
		
		
	}
	
}